package org.bozo.im.common.types;

import android.os.Parcel;
import android.os.Parcelable;

public class RawContact implements Parcelable {

	// ---------------------------------------------------------------------------------------
	// Enums
	// ---------------------------------------------------------------------------------------

	public enum Field {DISPLAY_NAME, PRESENCE};
	
	// ---------------------------------------------------------------------------------------
	// Variables
	// ---------------------------------------------------------------------------------------

	private String mDisplayName;
	private String mId;
	private long mContactId;
	private long mSystemId;
	private Presence mPresence;
	private Protocol mProtocol;

	// ---------------------------------------------------------------------------------------
	// Constructor
	// ---------------------------------------------------------------------------------------
	
	public RawContact() {
		mPresence = Presence.OFFLINE;
		mSystemId = -1;
	}
	
	// ---------------------------------------------------------------------------------------
	// Getters
	// ---------------------------------------------------------------------------------------

	public String getDisplayName() {
		return mDisplayName;
	}
	
	public String getId() {
		return mId;
	}

	public long getContactId() {
		return mContactId;
	}
	
	public long getSystemId() {
		return mSystemId;
	}

	public Presence getPresence() {
		return mPresence;
	}

	public Protocol getProtocol() {
		return mProtocol;
	}

	// ---------------------------------------------------------------------------------------
	// Setters
	// ---------------------------------------------------------------------------------------

	public void setDisplayName(String pDisplayName) {
		mDisplayName = pDisplayName;
	}
	
	public void setId(String pId) {
		mId = pId;
	}

	public void setContactId(long pContactId) {
		mContactId = pContactId;
	}

	public void setSystemId(long pSystemId) {
		mSystemId = pSystemId;
	}

	public void setPresence(Presence pPresence) {
		mPresence = pPresence;
	}

	public void setProtocol(Protocol pProtocol) {
		mProtocol = pProtocol;
	}

	// ---------------------------------------------------------------------------------------
	// Utils methods
	// ---------------------------------------------------------------------------------------
	
	public final boolean equals(Object pObj) {
		return (pObj instanceof RawContact
				&& getId().equals(((RawContact)pObj).getId())
				&& getProtocol() == ((RawContact)pObj).getProtocol());
	}
	
	public int hashCode() {
		return getId().hashCode() & getProtocol().hashCode();
	}
	
	// ---------------------------------------------------------------------------------------
	// Parcelable related methods
	// ---------------------------------------------------------------------------------------
	
	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel pParcel, int pFlags) {
		pParcel.writeString(getId());
		pParcel.writeLong(getSystemId());
		pParcel.writeLong(getContactId());
		pParcel.writeString(getDisplayName());
		pParcel.writeParcelable(getPresence(), 0);
		pParcel.writeParcelable(getProtocol(), 0);
	}

	public static final Parcelable.Creator<RawContact> CREATOR = new Creator<RawContact>() {

		public RawContact[] newArray(int pI) {
			return new RawContact[pI];
		}

		public RawContact createFromParcel(Parcel pParcel) {

			RawContact lRes = new RawContact();
			lRes.setId(pParcel.readString());
			lRes.setSystemId(pParcel.readLong());
			lRes.setContactId(pParcel.readLong());
			lRes.setDisplayName(pParcel.readString());
			lRes.setPresence((Presence)pParcel.readParcelable(getClass().getClassLoader()));
			lRes.setProtocol((Protocol)pParcel.readParcelable(getClass().getClassLoader()));

			return lRes;
		}
	};
}
